package id.link.win.login.sample.login;

import id.link.win.login.sample.login.dto.ChangePasswordDto;
import id.link.win.login.sample.login.dto.LoginRequestDto;
import id.link.win.login.sample.login.dto.LoginResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: Foy Lian
 * Date: 7/19/2019
 * Time: 11:32 AM
 */
@RestController
public class SampleLoginController {
    @PostMapping("/login")
    public LoginResult login(@RequestBody LoginRequestDto loginRequestDto) {
        if (loginRequestDto.getUsername().contains("idlink") ) {
            return LoginResult.ok();
        }
        if("administrator".equalsIgnoreCase(loginRequestDto.getUsername()) && "111111".equalsIgnoreCase(loginRequestDto.getPassword())){
            return LoginResult.ok();
        }
        return LoginResult.failure("登录失败，用户名包含idlink在试试,L)");
    }

    @PostMapping("/changePassword")
    public LoginResult changePassword(@RequestBody ChangePasswordDto changePasswordDto) {
        if (changePasswordDto.getSmsCode() != null && "666666".equalsIgnoreCase(changePasswordDto.getSmsCode())) {
            return LoginResult.ok().setMsg("短信改密成功！");
        }
        return LoginResult.failure("哈，改密失败。手动的哦");
    }
}
